let num = 1//用在动画上，让用户在第二次点击的时候可以接着上次转动的角度继续转
const app = getApp();
const http = require('../../../utils/http.js')
let filter = require('../../../utils/intercept.js')
Page(filter.identityFilter({
    data: {
        contShow: true,
        lottery: [],
        imgUrl: "",
        activityId: null
    },
    onLoad(opt) {
        this.checkAuth();
        var that = this
        // ----转盘显示列表---
        //查询限时
        http.get('/api/index/selectActivity', {type: 2}).then(res => {
            if (res.code == 200) {
                this.setData({
                    imgUrl: res.result.fileUrl,
                    activityId: res.result.id,
                    lottery: res.result.couponList
                })
                console.log(this.data.lottery);
            }
        })
        // this.setPlateData(); //执行设置转盘表面的文字
        let aniData = wx.createAnimation({
            timingFunction: 'ease-in-out',
            duration: 4000, //持续时间
            transformOrigin: '50% 0 50%'

        })
        that.aniData = aniData; //将动画对象赋值给this的aniData属性
    },

    startRollTap() { //开始转盘
        let that = this;
        http.get('/api/index/luckDraw', {activityId: this.data.activityId}).then(res => {
            if (res.code == 200) {
                let angle = res.result.angle //后台返回的旋转度数
                let aniData = that.aniData; //获取this对象上的动画对象
                aniData.rotate(-(360 * 2 + angle)).step();
                that.setData({
                    aniData: aniData.export()
                })
                num++;
                setTimeout(() => {
                    wx.showModal({
                        content: res.message,
                        showCancel: false,
                        success(res) {
                            if (res.confirm) {
                              that.reset()
                            }
                        }
                    })
                }, 3000)
            } else { //无法转动，直接弹框
                wx.showModal({
                    content: res.message,
                    showCancel: false
                })
            }
        });

    },
    tankuang: function (message, time) {
        // --弹框----
        setTimeout(function () {
            that.setData({
                times: message,
                isShowModel: true
            })
        }, time)
        setTimeout(function () {
            that.setData({
                times: message,
                isShowModel: false
            })
        }, time + 1500)
    },
    // --还原--
    reset: function () {
        this.aniData.rotate(0, 0)
            .scale(1)
            .translate(0, 0)
            .skew(0, 0)
            .step({duration: 0})
        this.setData({aniData: this.aniData.export()})
    },
    //验证权限
    checkAuth() {
        if (!app.globalData.userInfo.payOpenid) {
            //重定向到指定的页面
            wx.navigateTo({
                url: "/pages/auth/openid"
            });
            return;
        }
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
}))

